package com.itcast.n9_垃圾回收;

import java.io.IOException;
import java.lang.ref.SoftReference;

/**
 * @program: jvm
 * @description:
 * @author: flyduck
 * @create: 2024-09-30 10:16
 **/
public class Test07_常见的引用对象_演示内存不足时软引用里面的对象被回收 {
    public static void main(String[] args) throws IOException {

        byte[] bytes = new byte[1024 * 1024 * 100];
        SoftReference<byte[]> softReference = new SoftReference<byte[]>(bytes);
        bytes = null;
        //-Xmx200m：[B@6e0be858
        //-Xmx400m：[B@6e0be858
        System.out.println(softReference.get());

        byte[] bytes2 = new byte[1024 * 1024 * 100];
        //-Xmx200m：null
        //-Xmx400m：[B@6e0be858
        System.out.println(softReference.get());
    }
}
